<template>
  <div class="recently-container">
    <div class="products-timeline">
      <div class="products-row">
        <div v-for="product in tabsList.slice(0, 10)" :key="product.id" class="product-card">
          <a :href="`/product/${product.url}.html`" alt="product.name" :title="product.name" target="_self" style="color: #000;">
            <img :src="product.images[0]" :alt="product.name" class="product-image" />
          </a>
          <div class="product-info">
            <div class="product-price">{{ currencyStore.currentCurrency.unit }}{{proxy.$ConvertPrice( product.min_price )}}</div>
          </div>
        </div>
      </div>
      <!-- <div class="timeline-container">
        <div class="timeline-track">
          <div class="timeline-point" :class="{ active: hasToday }">
            <div class="label">Today</div>
          </div>
          <div class="timeline-point" :class="{ active: hasYesterday }">
            <div class="label">Yesterday</div>
          </div>
          <div class="timeline-point" :class="{ active: hasLastWeek }">
            <div class="label">Last Week</div>
          </div>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, computed ,getCurrentInstance} from 'vue'
import { useCartStore } from '@/store/cart'
import { useCurrencyStore } from '@/store/currency'
const currencyStore = useCurrencyStore()
const { proxy } = getCurrentInstance()
const cartStore = useCartStore()
const props = defineProps({
    tabsList: {
    type: Array,
    required: true
  }
})
interface Product {
  id: number
  name: string
  img: string
  min_price: number
  viewedAt: Date
}



const today = new Date()
const yesterday = new Date(today)
yesterday.setDate(yesterday.getDate() - 1)
const lastWeek = new Date(today)
lastWeek.setDate(lastWeek.getDate() - 7)

const hasToday = computed(() => {
  return props.tabsList.some(product => 
    // console.log('product', product)
    // viewedAt:1744167845983
    new Date(product.viewedAt).toDateString() === today.toDateString()
  )
})

const hasYesterday = computed(() => {
  return props.tabsList.some(product => 
    new Date(product.viewedAt).toDateString() === yesterday.toDateString()
  )
})

const hasLastWeek = computed(() => {
  return props.tabsList.some(product => {
    const viewDate = new Date(product.viewedAt)
    return viewDate > lastWeek && viewDate < yesterday
  })
})
</script>

<style lang="scss" scoped>
.recently-container {
  padding: 20px;
  max-width: 1300px;
  margin: 0 auto;
}

.products-timeline {
  .products-row {
    display: flex;
    overflow-x: auto;
    gap: 16px;
    padding: 4px;
    margin-bottom: 24px;
    scrollbar-width: none;
    &::-webkit-scrollbar {
      display: none;
    }
  }

  .product-card {
    flex: 0 0 auto;
    width: 110px;
    // border-radius: 4px;
    overflow: hidden;
    // box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;

    &:hover {
      transform: translateY(-4px);
    }

    .product-image {
      width: 105px;
      height: 140px;
      object-fit: cover;
    }

    .product-info {
      padding: 8px;

      .product-price {
        font-size: 14px;
        font-weight: 600;
        color: #333;
        text-align: center;
      }
    }
  }
}

.timeline-container {
  
  .timeline-track {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;

    &::before {
      content: '';
      position: absolute;
      left: 120px;
      right: 0;
      top: 50%;
      height: 1px;
      background: #eee;
      transform: translateY(-50%);
    }
  }

  .timeline-point {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
    opacity: 0.5;
    background: #fff;
    padding: 0 10px;

    &.active {
      opacity: 1;
      
      .label {
        background-color: rgb(247, 247, 247);
        border-color: rgb(238, 238, 238);
        color: #333;
        font-weight: 500;
        padding: 2px 30px;
        border-radius: 12px;
      }
    }

    .label {
      font-size: 12px;
      color: #666;
      white-space: nowrap;
      padding: 2px 30px;
    }
  }
}
</style>